package controller;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import service.EmployService;
import util.ImgUtils;
import entity.Employ;

@Controller
@RequestMapping("/employ/")
public class EmployController {
	@Autowired
	private EmployService es;
	@RequestMapping("add")
	public String toadd(String path,Model model){
		model.addAttribute("path", path);
		return  "employ/employadd";
	}
	@ResponseBody
	@RequestMapping("addsave")
	public String add(Employ employ){
		File file=new File(employ.getFace());
		JSONObject json=ImgUtils.check(file);
		try {
			employ.setFace((String) json.get("face"));
			es.add(employ);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "a";
		}
		return "main";
	}
	
}
